<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

		<title>Generatore ENTITY</title>

		<style>
			body{
				margin: 0px;
				padding: 0px;
				font-size: 10px;
				font-family: Verdana, Arial;
			}

			#content{
				padding-bottom:40px;
				padding-top: 10px;
				padding-left: 10px;
				padding-right: 10px;
			}

			#footer{
				height:20px;
				position:fixed;
				bottom:0px;
				width:100%;
				background:#F6F6F6;
				border-top:1px solid #C5C6C8;
				z-index:10000;
			}
			#footer #copyright{
				padding-top:2px;
				text-align:center;
				color:#666;
				font-family:Verdana;
				font-style:italic;
			}

			form .rowInput{
				overflow:hidden;
				margin-top:2px;
			}
			form .rowInput2{
				overflow:hidden;
				margin:10px 0px;
			}
			form .rowInput .labelField,
			form .rowInput2 .labelField{
				float:left;
				width:150px;
				padding-top:2px;
			}
			form .rowInput .inputField,
			form .rowInput2 .inputField{
				margin-left:155px;
			}

			input[type=text], input[type=password], textarea{
				border:1px solid #999;
				padding:3px 2px;
			}
			select{
				margin:1px 0px;
			}

			button{
				-moz-border-radius:4px;
				background:#F6F6F6 url(images/ui-bg_glass_100_f6f6f6_1x400.png) repeat-x scroll 50% 50%;
				border:1px solid #CCCCCC;
				color:#1C94C4;
				font-weight:bold;
				padding: 4px 15px;
				cursor:pointer;
			}
			button:hover{
				background:#FDF5CE url(images/ui-bg_glass_100_fdf5ce_1x400.png) repeat-x scroll 50% 50%;
				border:1px solid #FBCB09;
				color:#C77405;
				font-weight:bold;
			}
.title{
	padding: 0px 0px 5px 0px;
	border-bottom: 1px solid #999;
	margin-bottom: 10px;
	font-weight: bold;
}
.errorMess{
	color: FF0000;
	font-weight: bold;
}
		</style>
    </head>
    <body>
		<div id="content">
			<div class="title">Generatore automatico delle Entity e EntityManager prendendo le informazioni dal Database</div>
			<form name="entityGenerator" action="" method="post">
				<div class="rowInput">
					<div class="labelField">Host</div>
					<div class="inputField"><input type="text" name="host" size="30" /></div>
				</div>
				<div class="rowInput">
					<div class="labelField">Username</div>
					<div class="inputField"><input type="text" name="user" size="30" /></div>
				</div>
				<div class="rowInput">
					<div class="labelField">Password</div>
					<div class="inputField"><input type="text" name="pass" size="30" /></div>
				</div>
				<div class="rowInput">
					<div class="labelField">DB Name</div>
					<div class="inputField"><input type="text" name="db" size="30" /></div>
				</div><br />
				<div class="rowInput">
					<div class="labelField"><i>Opzioni generatore</i></div>
					<div class="inputField">
						<input name="option" type="radio" value="E">Solo Entity<br />
						<input name="option" type="radio" value="M">Solo Entity Manager<br />
						<input name="option" type="radio" value="EM" checked="checked">Entity e EntityManager
					</div>
				</div>
				<div class="rowInput">
					<div class="labelField"><i>Sovrascrivi se esiste</i></div>
					<div class="inputField">
						<select name="rewrite">
							<option value="S">Si</option>
							<option value="N">No</option>
						</select>
					</div>
				</div><br />
				<div class="rowInput">
					<div class="labelField">&nbsp;</div>
					<div class="inputField"><button type="submit">Genera</button></div>
				</div>
			</form>
		</div>
		<div id="footer">
			<div id="copyright">Generatore Entity per BXD Framework</div>
		</div>
	</body>
</html>

<?php

if(isset ($_POST) && count($_POST) > 0)
{
	if($_POST['host'] == "" || $_POST['user'] == "" || $_POST['pass'] == "" || $_POST['db'] == "")
		exit ("<p><center><font class='errorMess'>Completare la compilazione dei primi quattro campi per la confiugrazione della connessione al DATABASE</font></center></p>");

	//--> Paramentri per la connessione al database

	$db_host		= $_POST['host'];
	$db_username	= $_POST['user'];
	$db_password	= $_POST['pass'];
	$db_name		= $_POST['db'];

	$db = mysql_connect($db_host, $db_username, $db_password);

	if($db)
	{
		if(mysql_select_db($db_name, $db))
		{
			$option		= $_POST['option'];
			$rewrite	= $_POST['rewrite'];

			$allTable = mysql_query("SHOW TABLE STATUS");
			$numRows = mysql_num_rows($allTable);

			if($numRows > 0)
			{
				while($data = mysql_fetch_array($allTable))
				{
					$nameClass = getNameClass($data['Name']);

					if($option == "E" || $option == "EM") $table = mysql_query("SHOW COLUMNS FROM " . $data['Name']);
					if($option == "M" || $option == "EM") $table2 = mysql_query("SHOW COLUMNS FROM " . $data['Name']);

					if($option == "E" || $option == "EM") generateEntity($nameClass, $table, $data['Name'], $rewrite);
					if($option == "M" || $option == "EM") generateEntityManager($nameClass, $table2, $data['Name'], $rewrite);
				}

				echo "<p><center><b>Complete</b></center></p>";
			}
			else
				echo "<p><center><b>Complete</b></center></p>";
		}
		else
			echo "<p><center><font class='errorMess'>Errore nella selezione del DATABASE</font></center></p>";
	}
	else
		echo "<p><center><font class='errorMess'>Errore nella creazione della connessione. Verifica i parametri</font></center></p>";

	mysql_close($db);
}

//--> FUNZIONI PER LA CREAZIONE DELLE CLASSI

function getBindType($type)
{
	if(in_array($type, array("bit","tinyint","smallint","mediumint","int", "bigint", "float", "double", "decimal")))
		return "Int";

	if(in_array($type, array("date","datetime","timestamp","time","year","char","varchar","binary","varbinary","tinyblob","tinytext","blob","text","mediumblob","mediumtext","longblob","longtext","enum","set")))
		return "String";
}

function getTypeVar($string)
{
	if(strstr($string, "("))
	{
		$type = $string;

		$typeVar 	= strtoupper(substr($type, 0, strpos($type, "(")));
		$lengthVar	= substr($type, strpos($type, "(") + 1, (strpos($type, ")") - strpos($type, "(")) - 1);
	}
	else
	{
		$typeVar 	= strtoupper($string);
		$lengthVar	= "null";
	}

	return array("TYPE" => $typeVar, "LENGTH" => $lengthVar);
}

function getNameClass($string)
{
	$nameClass = "";

	if(strstr($string, "_"))
	{
		$nameClassArray = explode("_", $string);

		foreach ($nameClassArray as $value)
			$nameClass .= ucfirst($value);
	}
	else
		$nameClass = ucfirst($string);

	return $nameClass;
}

function getNameVar($string)
{
	$nameVar = "";

	if(strstr($string, "_"))
	{
		$nameFieldArray = explode("_", $string);

		$nameVar .= $nameFieldArray[0];

		for($i = 1; $i < count($nameFieldArray); $i++)
			$nameVar .= ucfirst($nameFieldArray[$i]);
	}
	else
		$nameVar = $string;

	return $nameVar;
}

function generateEntity($nameClass, $table, $tableName, $rewrite)
{
	if(($rewrite == "N" && !file_exists("../model/Entity" . $nameClass . ".php")) || $rewrite == "S")
	{
		$newClass = fopen("../model/Entity" . $nameClass . ".php", "w+");

		//--> INIZIALIZZO LA CLASSE PER LA ENTITY

		fwrite($newClass, "<?php\n");
		fwrite($newClass, "class Entity" . $nameClass . " extends Entity\n");
		fwrite($newClass, "{\n");

		$setGet				= "";
		$listPrivateVar		= "";
		$columnDescription	= "";
		$listRule			= "";

		while($field = mysql_fetch_array($table))
		{
			$nameVar = getNameVar($field['Field']);		//--> CALCOLO IL NOME DELLA VARIABILE
			$typeVar = getTypeVar($field['Type']);		//--> CALCOLO DEL TIPO DELLA VARIABILE

			$listPrivateVar .= "\t" . 'private $' . $nameVar . ";\n";

			$columnDescription .= "\t\t" . '$this->_addColumnDescription("' . $nameVar . '", "' . $field['Field'] . '", EntityType::' . $typeVar['TYPE'] . ', ' . ($typeVar['TYPE'] == "ENUM" ? "NULL" : $typeVar['LENGTH']) . ', ' . ($field['Null'] == "NO" ? "TRUE" : "FALSE") . ');' . "\n";

			if($typeVar['TYPE'] == "ENUM")
				$listRule .= "\t\t" . '$this->_addRule("' . $nameVar . '", Validator::VALIDATE_IN_VALUE, array(' . $typeVar['LENGTH'] . '));' . "\n";

			$setGet .= "\n\n\tpublic function get" . ucfirst($nameVar) . "()\n";
			$setGet .= "\t{\n";
			$setGet .= "\t\t" . 'return $this->' . $nameVar . ";\n";
			$setGet .= "\t}\n\n";
			$setGet .= "\tpublic function set" . ucfirst($nameVar) . '($' . $nameVar . ")\n";
			$setGet .= "\t{\n";
			$setGet .= "\t\t" . '$this->' . $nameVar . ' = $' . $nameVar . ";\n";
			$setGet .= "\t}";
		}

		fwrite($newClass, $listPrivateVar);

		//--> COSTRUTTORE

		fwrite($newClass, "\n\tpublic function  __construct()\n");
		fwrite($newClass, "\t{\n");
		fwrite($newClass, $columnDescription);
		if(strlen($listRule) > 0)
			fwrite($newClass, "\n" . $listRule);
		fwrite($newClass, "\t}");

		//--> GET TABLE NAME

		fwrite($newClass, "\n\n\tpublic function getTableName()\n");
		fwrite($newClass, "\t{\n");
		fwrite($newClass, "\t\treturn \"" . $tableName . "\";\n");
		fwrite($newClass, "\t}");

		//--> SET E GET

		fwrite($newClass, $setGet);

		fwrite($newClass, "\n}\n");
		fwrite($newClass, "?>");

		fclose($newClass);
	}
}

function generateEntityManager($nameClass, $table, $tableName, $rewrite)
{
	if(($rewrite == "N" && !file_exists("../model/Manager" . $nameClass . ".php")) || $rewrite == "S")
	{
		$newClassManager = fopen("../model/Manager" . $nameClass . ".php", "w+");

		//--> INIZIALIZZO LA CLASSE PER LA ENTITY MANAGER

		fwrite($newClassManager, "<?php\n");
		fwrite($newClassManager, "include_once '../model/Entity" . $nameClass . ".php';\n\n");
		fwrite($newClassManager, "class Manager" . $nameClass . " extends EntityManager\n");
		fwrite($newClassManager, "{\n");

		$primary		= "";		//--> INIZIALIZZO LA VARIABILE PER LA CHIAVE PRIMARIA
		$fieldDetail	= array();	//--> INIZIALIZZO LA VARIABILE PER IL DETTAGLIO DEI CAMPI

		while($field = mysql_fetch_array($table))
		{
			//--> CALCOLO IL NOME DELLA VARIABILE

			$nameVar = getNameVar($field['Field']);

			//--> CALCOLO DEL TIPO DELLA VARIABILE

			$typeVar = getTypeVar($field['Type']);

			/**--------- SCRIPT PER IL CALCOLO DELLE VARIABILI PER LA ENTITY MANAGER ---------**/

			if($field['Key'] == "PRI")
				$primary = array("field" => $field['Field'], "var" => $nameVar, "type" => strtolower($typeVar['TYPE']));

			$fieldDetail[] = array("key" => $field['Key'], "field" => $field['Field'], "var" => $nameVar, "type" => strtolower($typeVar['TYPE']));
		}

		//--> COSTRUTTORE

		fwrite($newClassManager, "\tpublic function __construct()\n");
		fwrite($newClassManager, "\t{\n");
		fwrite($newClassManager, "\t\tparent::__construct();\n");
		fwrite($newClassManager, "\t}\n\n");

		//--> CREATE

		$listVarsQuery = "(";
		$listBindVarsQuery = "(";

		foreach($fieldDetail as $fieldData)
		{
			if($fieldData['key'] != "PRI") $listVarsQuery .= $fieldData['field'];

			if(!(end($fieldDetail) == $fieldData) && $fieldData['key'] != "PRI") $listVarsQuery .= ", ";
		}
		$listVarsQuery .= ")";

		foreach($fieldDetail as $fieldData)
		{
			if($fieldData['key'] != "PRI") $listBindVarsQuery .= ":" . $fieldData['field'];

			if(!(end($fieldDetail) == $fieldData) && $fieldData['key'] != "PRI") $listBindVarsQuery .= ", ";
		}
		$listBindVarsQuery .= ")";


		fwrite($newClassManager, "\tpublic function create(" . '$' . "entity)\n");
		fwrite($newClassManager, "\t{\n");
		fwrite($newClassManager, "\t\t" . '$' . "query = \"INSERT INTO " . $tableName . " " . $listVarsQuery . " \";\n");
		fwrite($newClassManager, "\t\t" . '$' . "query.= \"VALUES " . $listBindVarsQuery . " \";\n\n");
		fwrite($newClassManager, "\t\tif (" . '$' . "this->db->prepareQuery(" . '$' . "query) !== FALSE)\n");
		fwrite($newClassManager, "\t\t{\n");

		foreach($fieldDetail as $fieldData)
			if($fieldData['key'] != "PRI") fwrite($newClassManager, "\t\t\t" . '$' . "this->db->bindParam" . getBindType($fieldData['type']) . "('" . $fieldData['field'] . "', " . '$' . "entity->get" . ucfirst($fieldData['var']) . "());\n");

		fwrite($newClassManager, "\n\t\t\tif (" . '$' . "this->db->executeQuery()===FALSE)\n");
		fwrite($newClassManager, "\t\t\t{\n");
		fwrite($newClassManager, "\t\t\t\t" . '$' . "error = " . '$' . "this->db->getLastError();\n");
		fwrite($newClassManager, "\t\t\t\tBXD::newException(\"DatabaseError\", " . '$' . "error[2]);\n");
		fwrite($newClassManager, "\t\t\t}\n\n");
		fwrite($newClassManager, "\t\t\t" . '$' . "entity->set" . ucfirst($primary['var']) . "(" . '$' . "this->db->getLastInsertId());\n");
		fwrite($newClassManager, "\t\t}\n");
		fwrite($newClassManager, "\t\telse\n");
		fwrite($newClassManager, "\t\t{\n");
		fwrite($newClassManager, "\t\t\t" . '$' . "error = " . '$' . "this->db->getLastError();\n");
		fwrite($newClassManager, "\t\t\tBXD::newException(\"DatabaseError\", " . '$' . "error[2]);\n");
		fwrite($newClassManager, "\t\t}\n");
		fwrite($newClassManager, "\t}\n\n");

		//--> READ

		fwrite($newClassManager, "\tpublic function read(" . '$' . "id)\n");
		fwrite($newClassManager, "\t{\n");
		fwrite($newClassManager, "\t\t" . '$' . "query  = \"SELECT * \";\n");
		fwrite($newClassManager, "\t\t" . '$' . "query .= \"FROM " . $tableName . " \";\n");
		fwrite($newClassManager, "\t\t" . '$' . "query .= \"WHERE " . $primary['field'] . " = :" . $primary['field'] . "\";\n\n");
		fwrite($newClassManager, "\t\tif (" . '$' . "this->db->prepareQuery(" . '$' . "query) !== FALSE)\n");
		fwrite($newClassManager, "\t\t{\n");
		fwrite($newClassManager, "\t\t\t" . '$' . "this->db->bindParam" . getBindType($primary['type']) . "('" . $primary['field'] . "', " . '$' . "id);\n\n");
		fwrite($newClassManager, "\t\t\tif(" . '$' . "this->db->executeQuery() !== FALSE)\n");
		fwrite($newClassManager, "\t\t\t{\n");
		fwrite($newClassManager, "\t\t\t\t" . '$' . "result = " . '$' . "this->db->getArrayAssocResult();\n\n");
		fwrite($newClassManager, "\t\t\t\tif (" . '$' . "result)\n");
		fwrite($newClassManager, "\t\t\t\t{\n");
		fwrite($newClassManager, "\t\t\t\t\treturn " . '$' . "this->entityUtils->fillEntity(new Entity" . $nameClass . "(), " . '$' . "result);\n");
		fwrite($newClassManager, "\t\t\t\t}\n");
		fwrite($newClassManager, "\t\t\t\telse\n");
		fwrite($newClassManager, "\t\t\t\t{\n");
		fwrite($newClassManager, "\t\t\t\t\tBXD::newException(\"NotFound\", \"Errore nel caricamento dei dati per la ENTITY: '" . $nameClass . "Entity' con elemento id = \" . " . '$' . "id);\n");
		fwrite($newClassManager, "\t\t\t\t}\n");
		fwrite($newClassManager, "\t\t\t}\n");
		fwrite($newClassManager, "\t\t\telse\n");
		fwrite($newClassManager, "\t\t\t{\n");
		fwrite($newClassManager, "\t\t\t\t" . '$' . "error = " . '$' . "this->db->getLastError();\n");
		fwrite($newClassManager, "\t\t\t\tBXD::newException(\"DatabaseError\", " . '$' . "error[2]);\n");
		fwrite($newClassManager, "\t\t\t}\n");
		fwrite($newClassManager, "\t\t}\n");
		fwrite($newClassManager, "\t\telse\n");
		fwrite($newClassManager, "\t\t{\n");
		fwrite($newClassManager, "\t\t\t" . '$' . "error = " . '$' . "this->db->getLastError();\n");
		fwrite($newClassManager, "\t\t\tBXD::newException(\"DatabaseError\", " . '$' . "error[2]);\n");
		fwrite($newClassManager, "\t\t}\n");
		fwrite($newClassManager, "\t}\n\n");

		//--> UPDATE

		$listVarsQuery = "";

		foreach($fieldDetail as $fieldData)
		{
			if($fieldData['key'] != "PRI") $listVarsQuery .= $fieldData['field'] . "=:" . $fieldData['field'];

			if(!(end($fieldDetail) == $fieldData) && $fieldData['key'] != "PRI") $listVarsQuery .= ", ";
		}

		fwrite($newClassManager, "\tpublic function update(" . '$' . "entity)\n");
		fwrite($newClassManager, "\t{\n");
		fwrite($newClassManager, "\t\t" . '$' . "query  = \"UPDATE " . $tableName . " SET " . $listVarsQuery . " \";\n");
		fwrite($newClassManager, "\t\t" . '$' . "query .= \"WHERE " . $primary['field'] . " = :" . $primary['field'] . "\";\n\n");
		fwrite($newClassManager, "\t\tif (" . '$' . "this->db->prepareQuery(" . '$' . "query) !== FALSE)\n");
		fwrite($newClassManager, "\t\t{\n");

		foreach($fieldDetail as $fieldData)
			if($fieldData['key'] != "PRI") fwrite($newClassManager, "\t\t\t" . '$' . "this->db->bindParam" . getBindType($fieldData['type']) . "('" . $fieldData['field'] . "', " . '$' . "entity->get" . ucfirst($fieldData['var']) . "());\n");

		fwrite($newClassManager, "\n\t\t\t" . '$' . "this->db->bindParam" . getBindType($primary['type']) . "('" . $primary['field'] . "', " . '$' . "entity->get" . ucfirst($primary['var']) . "());\n\n");
		fwrite($newClassManager, "\t\t\tif (" . '$' . "this->db->executeQuery()===FALSE)\n");
		fwrite($newClassManager, "\t\t\t{\n");
		fwrite($newClassManager, "\t\t\t\t" . '$' . "error = " . '$' . "this->db->getLastError();\n");
		fwrite($newClassManager, "\t\t\t\tBXD::newException(\"DatabaseError\", " . '$' . "error[2]);\n");
		fwrite($newClassManager, "\t\t\t}\n");
		fwrite($newClassManager, "\t\t}\n");
		fwrite($newClassManager, "\t\telse\n");
		fwrite($newClassManager, "\t\t{\n");
		fwrite($newClassManager, "\t\t\t" . '$' . "error = " . '$' . "this->db->getLastError();\n");
		fwrite($newClassManager, "\t\t\tBXD::newException(\"DatabaseError\", " . '$' . "error[2]);\n");
		fwrite($newClassManager, "\t\t}\n");
		fwrite($newClassManager, "\t}\n\n");

		//--> DELETE

		fwrite($newClassManager, "\tpublic function delete(" . '$' . "id)\n");
		fwrite($newClassManager, "\t{\n");
		fwrite($newClassManager, "\t\t" . '$' . "query  = \"DELETE FROM " . $tableName . " \";\n");
		fwrite($newClassManager, "\t\t" . '$' . "query .= \"WHERE " . $primary['field'] . " = :" . $primary['field'] . "\";\n\n");
		fwrite($newClassManager, "\t\tif (" . '$' . "this->db->prepareQuery(" . '$' . "query) !== FALSE)\n");
		fwrite($newClassManager, "\t\t{\n");
		fwrite($newClassManager, "\t\t\t" . '$' . "this->db->bindParam" . getBindType($primary['type']) . "('" . $primary['field'] . "', " . '$' . "id);\n\n");
		fwrite($newClassManager, "\t\t\tif (" . '$' . "this->db->executeQuery()===FALSE)\n");
		fwrite($newClassManager, "\t\t\t{\n");
		fwrite($newClassManager, "\t\t\t\t" . '$' . "error = " . '$' . "this->db->getLastError();\n");
		fwrite($newClassManager, "\t\t\t\tBXD::newException(\"DatabaseError\", " . '$' . "error[2]);\n");
		fwrite($newClassManager, "\t\t\t}\n");
		fwrite($newClassManager, "\t\t}\n");
		fwrite($newClassManager, "\t\telse\n");
		fwrite($newClassManager, "\t\t{\n");
		fwrite($newClassManager, "\t\t\t" . '$' . "error = " . '$' . "this->db->getLastError();\n");
		fwrite($newClassManager, "\t\t\tBXD::newException(\"DatabaseError\", " . '$' . "error[2]);\n");
		fwrite($newClassManager, "\t\t}\n");
		fwrite($newClassManager, "\t}\n\n");

		//--> READ ALL

		fwrite($newClassManager, "\tpublic function readAll()\n");
		fwrite($newClassManager, "\t{\n");
		fwrite($newClassManager, "\t\t" . '$' . "items = array();\n\n");
		fwrite($newClassManager, "\t\t" . '$' . "query  = \"SELECT * FROM " . $tableName . " WHERE true \";\n\n");
		fwrite($newClassManager, "\t\tif (" . '$' . "this->db->prepareQuery(" . '$' . "query))\n");
		fwrite($newClassManager, "\t\t{\n");
		fwrite($newClassManager, "\t\t\tif (" . '$' . "this->db->executeQuery() !== FALSE)\n");
		fwrite($newClassManager, "\t\t\t{\n");
		fwrite($newClassManager, "\t\t\t\tforeach(" . '$' . "this->db->getFetchAll() as " . '$' . "item)\n");
		fwrite($newClassManager, "\t\t\t\t\t" . '$' . "items[] = " . '$' . "this->entityUtils->fillEntity(new Entity" . $nameClass . "(), " . '$' . "item);\n");
		fwrite($newClassManager, "\t\t\t}\n");
		fwrite($newClassManager, "\t\t\telse\n");
		fwrite($newClassManager, "\t\t\t{\n");
		fwrite($newClassManager, "\t\t\t\t" . '$' . "error = " . '$' . "this->db->getLastError();\n");
		fwrite($newClassManager, "\t\t\t\tBXD::newException(\"DatabaseError\", " . '$' . "error[2]);\n");
		fwrite($newClassManager, "\t\t\t}\n");
		fwrite($newClassManager, "\t\t}\n");
		fwrite($newClassManager, "\t\telse\n");
		fwrite($newClassManager, "\t\t{\n");
		fwrite($newClassManager, "\t\t\t" . '$' . "error = " . '$' . "this->db->getLastError();\n");
		fwrite($newClassManager, "\t\t\tBXD::newException(\"DatabaseError\", " . '$' . "error[2]);\n");
		fwrite($newClassManager, "\t\t}\n\n");
		fwrite($newClassManager, "\t\treturn " . '$' . "items;\n");
		fwrite($newClassManager, "\t}\n\n");

		//--> COUNT ALL

		fwrite($newClassManager, "\tpublic function countAll()\n");
		fwrite($newClassManager, "\t{\n");
		fwrite($newClassManager, "\t\t" . '$' . "query = \"SELECT COUNT(*) AS COUNT_ROW FROM " . $tableName . " WHERE true \";\n\n");
		fwrite($newClassManager, "\t\t" . '$' . "this->db->prepareQuery(" . '$' . "query);\n");
		fwrite($newClassManager, "\t\t" . '$' . "this->db->executeQuery();\n\n");
		fwrite($newClassManager, "\t\t" . '$' . "result = " . '$' . "this->db->getArrayAssocResult();\n\n");
		fwrite($newClassManager, "\t\treturn " . '$' . "result['COUNT_ROW'];\n");
		fwrite($newClassManager, "\t}");

		fwrite($newClassManager, "\n}\n");
		fwrite($newClassManager, "?>");

		fclose($newClassManager);
	}
}
?>